import React from 'react';
import { connect } from 'dva';
import PropTypes from 'prop-types';
import {Button,Row,Col,Layout,Icon,Form,Input,message,} from 'antd';
// import reqwest from 'reqwest';
import {Link} from 'dva/router';
// import {reqwest_get} from '../../utils/Reqwest.js'
// import style from '../../styles/ResetInput.less';
// import inStyle from '../../styles/Info.less'
import acct from '../Acct.less'
// import {numvail,selectvail} from '../../utils/Validator.js'
// import { Editor } from 'react-draft-wysiwyg'
import {reqwest_get,reqwest_post} from '../../../utils/Reqwest.js'
// import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css';
const FormItem = Form.Item;
class AcctSave extends React.Component{
	constructor(props){
		super(props);
		// console.log(props)
		this.state={
			list:props.list,
			loading:false,
		}
	}
	handleSubmit(e){
		e.preventDefault();
		let _this = this;
		this.setState({loading:true})
		this.props.form.validateFields((err, values) => {
		let _value=values;
        _value.access_token=window.localStorage['token'];
        if (!err) {
			reqwest_post('/api/strategy_results/'+_this.props.save.usr,{
				access_token:window.localStorage['token'],
				strategy_result:values
			},(data)=>{
				// console.log(data)
				// _this.context.router.goBack()
				message.success('修改成功')
				_this.props.callback(data.sr,_this.props.event)
				// _this.props.list = data.sr
				_this.context.router.push('/app/acct_list?current='+_this.props.current+'&typ=list&usr='+_this.props.save.usr)
			})

      }else{
        message.warning('请输出必填项');
      }
    });
        this.setState({loading:false})

	}
	componentWillMount(){

	}
	render(){
		// console.log(123)

		const {list,order} =this.state;
    // const _remark = JSON.parse(list.remark)
    const formItemLayout = {
      labelCol: { span: 7},
      wrapperCol: { span: 17 },
      style:{minWidth:200}
    };
    // console.log(this.props)
  	const {getFieldDecorator}=this.props.form;
		return(
			<Form className={acct.flex} onSubmit={this.handleSubmit.bind(this)}>
				<Row >
				<Col span={10}>
					<span>
						销售提成：
					</span>
					<span >
						<FormItem>
							{getFieldDecorator('saler_rate_amount', {
								initialValue:this.props.list.saler_rate_amount
		          })(
								<Input  />
							)}
						</FormItem>
					</span>
				</Col>
				<Col span={10}>
					<span>
						销售主管提成：
					</span>
					<span >
						<FormItem>
							{getFieldDecorator('saler_director_rate_amount', {
								initialValue:this.props.list.saler_director_rate_amount
		          })(
								<Input  />
							)}
						</FormItem>
					</span>
				</Col>
				<Col span={10}>
					<span>
						介绍人返利：
					</span>
					<span>
						{this.props.list.introducer_rebate_amount}
					</span>
				</Col>
				<Col span={10}>
					<span>
						运营提成：
					</span>
					<span>
						<FormItem>
							{getFieldDecorator('operator_amount', {
								initialValue:this.props.list.operator_amount
		          })(
								<Input  />
							)}
						</FormItem>
					</span>
				</Col>
				<Col span={10}>
					<span>
						售后提成：
					</span>
					<span>
						<FormItem>
							{getFieldDecorator('cs_director_amount', {
								initialValue:this.props.list.cs_director_amount
		          })(
								<Input  />
							)}
						</FormItem>
					</span>
				</Col>
				<Col span={10}>
					<span>
						企划提成：
					</span>
					<span>
						<FormItem>
							{getFieldDecorator('planinger_director_amount', {
								initialValue:this.props.list.planinger_director_amount
		          })(
								<Input  />
							)}
						</FormItem>
					</span>
				</Col>
				</Row>
				<Row >
		 		<Col  sm={{span :8,pull:0}} xs={{span:17,pull:0}}  style={{marginTop:10}} >
		   		<div  style={{float:'left'}} >
		   			<FormItem >
		          <Button loading={this.state.loading} htmlType="submit" size='large' type="primary"  >
		            确认修改
		          </Button>
		      	</FormItem>
		      </div>
		      <div  style={{float:'left',marginLeft:10}} >
		      	<FormItem>
		      	<Button size='large'  >
		          <Link to={{pathname:'/app/acct_list',query:{current:this.props.current,typ:'list',usr:this.props.save.usr}}}>取消</Link>
		        </Button>
		        </FormItem>
		      </div>
		    </Col>
		  </Row> 
		  </Form> 
		)
	}
}

const AcctSaveForm = Form.create()(AcctSave);
AcctSave.contextTypes = {
  router: PropTypes.object
};
export default connect()(AcctSaveForm)